package de.tudarmstadt.ukp.wikisniffer.userstudy.gui.intro;

import java.io.IOException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import de.tudarmstadt.ukp.wikisniffer.userstudy.Client;
import de.tudarmstadt.ukp.wikisniffer.userstudy.gui.questions.util.LearnTimer;
import de.tudarmstadt.ukp.wikisniffer.userstudy.gui.rtool.util.RToolTimer;




@SuppressWarnings("serial")
public class PrepareForQuestionGui extends TextGuiWithoutButton {
	
	private ExecutorService service;
	
	private Thread timer;
	private boolean isTrialRun = false;
	
	public PrepareForQuestionGui(boolean isTrialrun) 
	{
		this.isTrialRun = isTrialrun;
	}
	
	@Override
	public void open(){
		//buttonLabel = "Fragen beantworten";  
		super.open();
		
		try {
			Client.client.resultStore.saveAction("Started preparing for Question");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		//if Timer with RTool should be used
		if(Client.rToolActivated && !this.isTrialRun) 
			timer = new RToolTimer(Client.timeoutInMinutesForSniffer);	
		//if common Timer should be used
		else 
			timer = new LearnTimer();
		
		service = Executors.newCachedThreadPool();
		service.execute(timer);
	}
	
	@SuppressWarnings("deprecation")
	@Override
	public void close(){
		super.close();
		service.shutdownNow();
		try {
			Client.client.resultStore.saveAction("Finished preparing for Question");
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
